"""辅助流程工具。

提供一个安全的 run() 协调函数，用于非破坏性地检查配置与数据加载。
该函数不会写入磁盘，仅尝试读取 `config.yaml` 并调用 `src.core_utils.load_data()`（若可用）。
"""

from pathlib import Path
from typing import Tuple

def run() -> Tuple[bool, str]:
	"""Run a safe check: read config and attempt to load data.

	Returns (success, message).
	"""
	try:
		repo_root = Path(__file__).resolve().parents[1]
		cfg_path = repo_root / 'config.yaml'
		if not cfg_path.exists():
			return False, 'config.yaml not found'
		# lazy import core_utils
		try:
			from src.core_utils import load_data
		except Exception:
			return False, 'src.core_utils.load_data not available'

		try:
			df = load_data()
			rows = len(df)
			cols = len(df.columns)
			msg = f'load_data 成功，rows={rows} cols={cols}'
			print(msg)
			return True, msg
		except FileNotFoundError as e:
			msg = f'load_data 未找到文件：{e}'
			print(msg)
			return False, msg
		except Exception as e:
			msg = f'load_data 出错：{e}'
			print(msg)
			return False, msg
	except Exception as e:
		return False, str(e)
